Skip to content

Optmize email normalization #6557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025

Conversation

akatsoulas
Copy link
Collaborator

Avoids to call the normalzie_gmail function twice

@akatsoulas akatsoulas requested review from escattone and Copilot March 12, 2025 09:48
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes email normalization by preventing duplicate calls to the normalize_gmail function. It removes the redundant is_valid_email function and replaces the logic within send_messages to iterate through recipient emails only once, while also adding a test to verify that invalid emails are filtered out.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
kitsune/sumo/tests/test_email_utils.py Added a test case to validate that invalid emails are removed correctly.
kitsune/sumo/email_utils.py Removed the is_valid_email function and refactored send_messages to normalize and validate emails in a single pass.

send_messages_mock = mock_mail.get_connection().__enter__().send_messages
send_messages_mock.assert_called_once_with(messages)
# Check that the invalid email was removed
self.assertEqual(messages[0].to, ["valid@example.com", "another.valid@example.com"])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another.valid@example.com is a valid email address. invalid.@example.com is not. The need for the gmail normalization is because for gmail addresses with dots (.) are the same. This is not true for other systems

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, the original test above did test an invalid email address ("ringo").

@akatsoulas akatsoulas merged commit 5f456e2 into mozilla:main Mar 12, 2025
2 checks passed
@akatsoulas akatsoulas deleted the optimize-email-normalization branch March 12, 2025 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants